
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author GON
 */
public class fileSendTest {

    fileSendTest() {
        try {
            Socket socket = new Socket("127.0.0.1", 1000);
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));;
            bw.write("fileAttachedXXXpoxvie");
            bw.newLine();
            bw.flush();
            File file = new File("test.txt");
            byte[] mybytearray = new byte[(int) file.length()];
            System.out.println(file.length());
            FileInputStream fis = new FileInputStream(file);
            BufferedInputStream bis = new BufferedInputStream(fis);
            bis.read(mybytearray, 0, mybytearray.length);
            OutputStream os = socket.getOutputStream();
            System.out.println("sending...");
            os.write(mybytearray, 0, mybytearray.length);
            os.flush();
            System.out.println("File sent");
        } catch (UnknownHostException ex) {
            Logger.getLogger(fileSendTest.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(fileSendTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void main(String args[]){
        new fileSendTest();
    }
}
